package com.qidianit.mes.production.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.common.util.Constant;
import com.qidianit.mes.pojo.Process;
import com.qidianit.mes.pojo.ProcessSteps;
import com.qidianit.mes.production.mapper.ProcessStepMapper;
import com.qidianit.mes.production.service.ProcessStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author djl
 * @Time 2024/10/17 9:55
 */
@Service
public class ProcessStepServiceImpl implements ProcessStepService {
    @Autowired
    private ProcessStepMapper processStepMapper;

    @Override
    public MESResult showProcessStep(String processId,int page, Integer limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<ProcessSteps> processSteps = processStepMapper.listByProcessId(processId);
        PageInfo<ProcessSteps> pageInfo = new PageInfo<>(processSteps);
        // 将pageInfo对象设置到qdResult中
        return MESResult.success(pageInfo);
    }

    @Override
    public MESResult listProcessStep(String processId) {
        return MESResult.success(processStepMapper.listByProcessId(processId));
    }

    @Override
    public MESResult countProcessSteps(String processId) {
        return MESResult.success(processStepMapper.countProcessSteps(processId));
    }

    @Override
    public MESResult addNewStep(ProcessSteps processSteps) {
        if(processStepMapper.selectByProcessIdAndStepId(processSteps.getProcessId(),processSteps.getProcessStepId()) == null){
            processStepMapper.addNewStep(processSteps);
            return MESResult.success(Constant.RESPONSE_STATUS_OK);
        }
        return MESResult.error(Constant.RESPONSE_STATUS_REPEAT);
    }

    @Override
    public MESResult editStep(ProcessSteps processSteps,int beforeStepId) {
        System.out.println(processSteps);
        return MESResult.success(200,"OK",processStepMapper.editStep(processSteps,beforeStepId));
    }

    @Override
    public MESResult deleteStep(String processId, int processStepId) {
        return MESResult.success(200,"OK",processStepMapper.deleteStep(processId,processStepId));
    }

    @Override
    public MESResult reDelete(int[] stepIds, String processId) {
        return MESResult.success(200,"OK",processStepMapper.reDelete(stepIds,processId));
    }

    @Override
    public MESResult showByOperationStepId(Integer operationStepId) {
        return MESResult.success(processStepMapper.showByOperationStepId(operationStepId));
    }

}
